import { Redirect, Route } from "react-router";

export default function AuthRouter({ path, component: Com }) {
  return (
    <Route
      path={path}
      render={(props) => {
        const token = localStorage.getItem("geek-pc");
        if (token) {
          return <Com {...props} />;
        } else {
          return (
            <Redirect
              to={{ pathname: "/login", state: { form: props.location } }}
            />
          );
        }
      }}
    />
  );
}
